import { GATEWAY_IP, PORT } from './address'
import httpRequest from '../utils/httpRequest'

/**
 * 用户登录
 * 
 * @param {*} data 
 * @returns 
 */
export const userLogin = (data) => {
    return new Promise((resolve,reject) => {
        httpRequest({
            url : `http://${GATEWAY_IP}:${PORT}/gateway/user/userinfo/login`,
            method : 'post',
            data : data
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}
/**
 * 用户信息
 * 
 * @returns 
 */
export const getUserInfo = () => {
    return new Promise((resolve,reject) => {
        httpRequest({
            url : `http://${GATEWAY_IP}:${PORT}/gateway/user/userinfo/getuser/1`,
            method : 'get',
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}
/**
 * 用户注册
 * 
 * @param {*} data 
 * @returns 
 */
export const userRegister = (data) => {
    return new Promise((resolve,reject) => {
        httpRequest({
            url : `http://${GATEWAY_IP}:${PORT}/gateway/user/userinfo/register`,
            method : 'post',
            data : data
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}
/**
 * 获取用户地址
 * 
 * @param {*} userId 
 * @returns 
 */
export const getUserAddress = (userId) => {
    return new Promise((resolve,reject) => {
        httpRequest({
            url : `http://${GATEWAY_IP}:${PORT}/gateway/user/address/getuseraddress/${userId}`,
            method : 'get',
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}
/**
 * 保存资讯
 * 
 * @param {*} data 
 * @returns 
 */
export const informationSave = (data) => {
    return new Promise((resolve,reject) => {
        httpRequest({
            url : `http://${GATEWAY_IP}:${PORT}/gateway/user/information/save`,
            method : 'post',
            data : data
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}
/**
 * 获取资讯列表
 * 
 * @param {*} page 
 * @returns 
 */
export const informationList = (page) => {
    return new Promise((resolve,reject) => {
        httpRequest({
            url : `http://${GATEWAY_IP}:${PORT}/gateway/user/information/list/${page}`,
            method : 'get',
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}
/**
 * 更改密码
 * 
 * @param {*} page 
 * @returns 
 */
 export const updatePassword = (data) => {
    return new Promise((resolve,reject) => {
        httpRequest({
            url : `http://${GATEWAY_IP}:${PORT}/gateway/user/userinfo/updatePassword`,
            method : 'post',
            data : data
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}